'''
Desc: 
Author: 陈爱国
Date: 2024-09-19 09:46:53
'''
import cv2
from ultralytics import YOLO

# 加载YOLO V8的模型
model_path=""
model = YOLO("./pt/yolov8n.pt")

# 加载视频流
stream_source=""
cap = cv2.VideoCapture("./data/car.mp4")

# 循环视频流
while cap.isOpened():
    # 从视频中读取一帧
    success, frame = cap.read()

    if success:
        # 对视频帧进行推理
        res = model(frame)

        # 将结果可视化为一个OpenCV可显示的frame
        annotated_frame = res[0].plot()

        # 显示结果
        cv2.imshow("YOLOv8 Inference", annotated_frame)

        # 退出视频
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    else:
        # 结束循环
        break

# 释放VideoCapture对象并关闭显示窗口
cap.release()
cv2.destroyAllWindows()
